package com.t19;

import java.util.Random;

/**
 * Created by xuyiwei on 2018/9/12.
 */
public class Enums {
    private static Random rand = new Random(47);
    public static <T extends Enum<T>> T random(Class<T> ec){
        //得到该枚举的所有构造函数类型
        return random(ec.getEnumConstants());
    }
    public static <T> T random(T[] values) {
        //根据构造函数返回枚举的随机值
        return values[rand.nextInt(values.length)];
    }
}
